package _05SingleTonDesignPattern;

/**
 * 双重判断
 */
public class Person2 {
    private String name;
    private static Person2 person;
    private Person2(){

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static  Person2 getPerson(){
       if(person==null)  //这个比懒汉式效率更高，当有多个线程
           synchronized(Person2.class){
           person=new Person2();
       }
       return person;
    }
}
